package gameservice

import (
	"admin100/app/dao/gamedao"
	"admin100/library/define"
	"admin100/library/define/defErr"

	"github.com/gogf/gf/frame/g"
)

var Account = &accountService{}

type accountService struct {
}

//获取总创角色人数
func (s *accountService) GetTotalRegisterRoleCountByChannelList(node, serverId string, channelList []string) int {
	gameDb := gamedao.NewAccountDao(node)
	i, err := gameDb.Where(g.Map{
		gameDb.Columns.ServerId: serverId,
		gameDb.Columns.Channel:  channelList,
	}).Count()
	defErr.IfPanic(err, define.DataOptFail)

	return i
}

//获取总创角人数
func (s *accountService) GetTotalCreateRoleCountByChannelList(node, serverId string, channelList []string) int {
	gameDb := gamedao.NewAccountDao(node)
	i, err := gameDb.WhereValNotEmpty(g.Map{
		gameDb.Columns.ServerId:     serverId,
		gameDb.Columns.IsCreateRole: 1,
		gameDb.Columns.Channel:      channelList,
	}).Count()
	defErr.IfPanic(err, define.DataOptFail)
	return i
}

//
func (s *accountService) GetCreateRoleCountByChannelList(node, serverId string, channelList []string, startTime, endTime int) int {
	gameDb := gamedao.NewAccountDao(node)
	i, err := gameDb.Where(g.Map{
		gameDb.Columns.IsCreateRole:              1,
		gameDb.Columns.ServerId:                  serverId,
		gameDb.Columns.Channel:                   channelList,
		gameDb.Columns.Time + " between ? and ?": g.Slice{startTime, endTime},
	}).Count()
	defErr.IfPanic(err, define.DataOptFail)
	return i
}

//获取时间内注册人数
func (s *accountService) GetRegisterRoleCountByChannelList(node, serverId string, channelList []string, startTime, endTime int) int {
	gameDb := gamedao.NewAccountDao(node)
	i, err := gameDb.Where(g.Map{
		gameDb.Columns.ServerId:                  serverId,
		gameDb.Columns.Channel:                   channelList,
		gameDb.Columns.Time + " between ? and ?": g.Slice{startTime, endTime},
	}).Count()
	defErr.IfPanic(err, define.DataOptFail)
	return i
}
